<template>
  <basic-dialog
    :visible.sync="spplierVisible"
    :title="'查看供应商'"
    :width="'50%'"
    :handleClose="handleCloseDialog"
    :handleOpen="handleOpenDialog"
    :showFooter="false"
  >
    <BasicTable
      :showTotal="false"
      :dataSource="tableInfo.list"
      :columns="tableInfo.columns"
      :loading="tableInfo.loading"
      :tableHeight="480"
    />
  </basic-dialog>
</template>
<script>
import BasicDialog from '@/components/BasicDialog';
import BasicTable from '@/components/skusTable';
import { querySpplierListService } from '@api/stock/stockOverflow';

export default {
  name: 'SpplierDialog', // 查看供应商
  components: {
    BasicDialog,
    BasicTable,
  },
  props: {
    spplierVisible: {
      type: Boolean,
      default: false
    },
    itemId: {
      type: Number
    }
  },
  data () {
    return {
      tableInfo: {
        list: [],
        columns: [
          {
            title: '供应商编码',
            key: 'supplyUuid',
          },
          {
            title: '供应商名称',
            key: 'supplyName',
          },
        ],
        loading: false
      },
    };
  },
  methods: {
    handleOpenDialog () {
      this.getTableData()
    },
    // 关闭弹框
    handleCloseDialog () {
      this.$emit('update:spplierVisible', false);
    },
    // 获取表格数据
    async getTableData () {
      const res = await querySpplierListService(
        { id: this.itemId },
        state => { this.tableInfo.loading = state }
      );
      if (res?.retData) {
        this.tableInfo.list = res.retData;
      }
    },
  }
};
</script>
